
define([
       ]
       ,

       function()
       {
           var processIncomingMessage = function(msg)
           {
               alert("A new message arrived:" + msg);
           }

           var wsport = "9000";

           var websocketUrl = "ws://"+ location.host + ":" + wsport;
           var websocket = new WebSocket(websocketUrl);



           websocket.onopen = function () {
               //alert("The socket is open!");
           };

           websocket.onclose = function() {
               //alert("Closed...");
           };

           // Log errors
           websocket.onerror = function (error) {
               //alert("An error occured...");
           };

           // Log messages from the server
           websocket.onmessage = function (e)
           {
               processIncomingMessage(e.data);
           };

           return {
               websocket: websocket,
               requestId: 0,

               request: function(req)
               {
                   req.id = this.requestId;
                   this.requestId++;
                   this.websocket.send(JSON.stringify(req));
               }
           }
       }
)


